using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Mvc.Mailer;
using System.Net.Mail;
using xConnected.Core.Model.ViewModel;
using xConnected.Service;

namespace xConnected.Mailers
{ 
    public class UserMailer : MailerBase, IUserMailer     
	{
		public UserMailer():
			base()
		{
			MasterName="_Layout";
		}

		private readonly UserService _userService;
        public UserMailer(UserService userService)
        {
            _userService = userService;
        }

		public virtual MailMessage Welcome()
		{
			var mailMessage = new MailMessage{Subject = "Welcome"};
			mailMessage.To.Add("gorgieva.sandra88@gmail.com");
			PopulateBody(mailMessage, viewName: "Welcome");

			return mailMessage;
		}
        public virtual MailMessage Welcome(string email,string username,Guid activationKey)
        {
            var mailMessage = new MailMessage { Subject = "Welcome" };

            mailMessage.To.Add(email);
            ViewBag.Url = String.Format("{0}{1}{2}", ConfigurationSettings.AppSettings["HostDomain"], "#/?activationKey=", activationKey);
            ViewBag.ActivationKey = activationKey ;
            ViewBag.Username = username;
            PopulateBody(mailMessage, viewName: "Welcome");

            return mailMessage;
        }

        public virtual MailMessage Contact(int id,ContactModel model)
        {
            var mailMessage = new MailMessage { Subject = model.Subject};
            var userEmail = _userService.GetById(id).Email;
            var username = _userService.GetById(id).Username;
            mailMessage.To.Add(userEmail);
            ViewBag.Username = username;
            ViewBag.Email = model.Email;
            ViewBag.Body = model.Body;
            PopulateBody(mailMessage, viewName: "Contact");

            return mailMessage;
        }

		public virtual MailMessage GoodBye()
		{
			var mailMessage = new MailMessage{Subject = "GoodBye"};
			
			//mailMessage.To.Add("some-email@example.com");
			//ViewBag.Data = someObject;
			PopulateBody(mailMessage, viewName: "GoodBye");

			return mailMessage;
		}

		
	}
}